
function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.getFullName = function () {
        return this.firstName + " " + this.lastName;
    }
}

// var javaClass = Java.type("com.limi.util.NashornSample");
// var person = new Person("Limi", "Pan");
// javaClass.fun4(person);

//Array
var IntArray = Java.type("int[]");
var array = new IntArray(5);
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;
array[4] = 5;

try{
    array[5] = 21;
}catch (e) {
    print(e.message);
}

//ArrayList
var ArrayList = Java.type("java.util.ArrayList");
var list= new ArrayList();
list.add("a");
list.add("b");
list.add("c");
for each (var el in list) print(el);

//map
var map = new java.util.HashMap();
map.put("foo", "val1");
map.put("bar", "val2");
for each (var k in map.keySet()) print(k);
for each (var v in map.values()) print(v);

//lambda、streams
var list2 = new java.util.ArrayList();
list2.add("ddd2");
list2.add("aaa2");
list2.add("bbb1");
list2.add("aaa1");
list2.add("bbb3");
list2.add("ccc");
list2.add("bbb2");
list2.add("ddd1");

list2
    .stream()
    .filter(function (el) {
        return el.startsWith("aaa");
    })
    .sorted()
    .forEach(function (el) {
        print(el);
    });